/**
 * This file is part of 1genia trampoline
 * Copyright (C) 2007 1genia (contact@1genia.com)
 *
 * This library is free software; you can redistribute it and/or modify
 * it under the terms of the GNU Lesser General Public License as
 * published by the Free Software Foundation; version 3 of the License. 
 *
 * This library is distributed in the hope that it will be useful, but
 * WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Library General Public License for more details. 
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; see the file COPYING.TXT.  If not,
 * write to the Free Software Foundation, Inc., 51 Franklin Street,
 * Fifth Floor, Boston, MA 02110-1301, USA. 
 **/
package com.genia.toolbox.web.gwt.basics.client.log.impl;

import com.genia.toolbox.web.gwt.basics.client.log.Logger;

/**
 * the base implementation of <code>Logger</code>.
 */
public abstract class AbstractLogger
    implements Logger
{
  /**
   * the current level of this Logger.
   */
  private Level level = Level.ALL;



  /**
   * log a message at the debug level.
   * 
   * @param message
   *          the message to log
   */
  public void debug(final String message)
  {
    log(message, Level.DEBUG);
  }



  /**
   * abstract method that really log the message. All the tests have already
   * been performed.
   * 
   * @param message
   *          the message to log
   * @param level
   *          the level of the message
   */
  public abstract void doLog(String message, Level level);



  /**
   * log a message at the error level.
   * 
   * @param message
   *          the message to log
   */
  public void error(final String message)
  {
    log(message, Level.ERROR);
  }



  /**
   * log a message at the fatal level.
   * 
   * @param message
   *          the message to log
   */
  public void fatal(final String message)
  {
    log(message, Level.FATAL);
  }



  /**
   * getter for the level property.
   * 
   * @return the level
   */
  public Level getLevel()
  {
    return level;
  }



  /**
   * log a message at the info level.
   * 
   * @param message
   *          the message to log
   */
  public void info(final String message)
  {
    log(message, Level.INFO);
  }



  /**
   * log a message at the given level.
   * 
   * @param message
   *          the message to log
   * @param level
   *          the level of the message
   */
  public void log(final String message, final Level level)
  {
    if (this.level.mustLog(level)) {
      doLog(message, level);
    }
  }



  /**
   * set the level of this logger. A logger will log all message of priority
   * greater or equals of its level.
   * 
   * @param level
   *          the level to set
   */
  public void setLevel(final Level level)
  {
    this.level = level;
  }



  /**
   * log a message at the trace level.
   * 
   * @param message
   *          the message to log
   */
  public void trace(final String message)
  {
    log(message, Level.TRACE);
  }



  /**
   * log a message at the warn level.
   * 
   * @param message
   *          the message to log
   */
  public void warn(final String message)
  {
    log(message, Level.WARN);
  }

}
